const state = {
  userName: '',  // 用户名称
  username: '',  // 用户名称
  dynamicsPage: [], // 动态页面，不显示菜单
  token: '',     // token
  version: '',     // version
  baseApi: '/api',
  number: 0, // 有效数量
  user: {},     // 用户信息
  role: '',     // 角色
  orgCode: '',     // 机构
  refresh: true, // 刷新
  menus: false, // 菜单
  appConfig: null, // app 配置
  phone: ''    // 手机号
}
const mutations = {
  setUserName(state, name) {
    state.userName = name
  },
  setUsername(state, name) {
    state.username = name
  },
  clearDynamicsPage() {
    state.dynamicsPage = []
  },
  addDynamicsPage(state, dynamicsPage) {
    state.dynamicsPage.push(dynamicsPage)
  },
  setVersion(state, version) {
    state.version = version
  },
  setNumber(state, num) {
    state.number = num
  },
  setToken(state, newToken) {
    state.token = newToken
  },
  setRole(state, role) {
    state.role = role
  },
  setOrgCode(state, orgCode) {
    state.orgCode = orgCode
  },
  setRefresh(state, flag) {
    state.refresh = flag
  },
  setMenus(state, menus) {
    state.menus = menus
  },
  setPhone (state, phone) {
    state.phone = phone
    if (phone) {
      localStorage.setItem('config-user-phone', phone)
    } else {
      localStorage.removeItem('config-user-phone')
    }
  },
  setUserInfo (state, user) {
    state.user = user
  },
  setAppConfig (state, info) {
    state.appConfig = info
  }
}
const actions = {
  // 设置name
  setUserName({ commit }, name) {
    commit('setUserName', name)
  }
}
export default {
  state,
  mutations,
  actions
}
